package com.rq.adapter;

import android.view.View;
import android.widget.Toast;

import com.rq.rvlibrary.AdapterHolderController;
import com.rq.rvlibrary.AdapterHolderControllerHelper;
import com.rq.rvlibrary.BaseAdapter;
import com.rq.rvlibrary.BaseViewHolder;
import com.rq.rvlibrary.OnClick;
import com.rq.rvlibrary.OnInterceptClick;

import java.util.List;

public class ExampleRedViewHolder extends BaseViewHolder<MoreData> implements AdapterHolderController,
        OnInterceptClick {

    public ExampleRedViewHolder(View itemView) {
        super(itemView);
    }

    @Override
    public int inflateLayoutId() {
        return R.layout.item_red;
    }

    @Override
    public void fillData(BaseAdapter adapter, int position, MoreData o) {
        super.fillData(adapter, position, o);
        setItemText(R.id.txt, o.name + "--" + o.age);
    }

    AdapterHolderControllerHelper controllerHelper;

    @Override
    public void setDataPasser(AdapterHolderControllerHelper helper) {
        this.controllerHelper = helper;
    }

    @OnClick({R.id.txt})
    public boolean intercept(Object object, View view, int position) {
        if (object instanceof String) {
            if (((String) object).contains("33") && position > 0) {// controllerHelper != null &&
                Toast.makeText(view.getContext(), "点击了非首条含33的数据:" + object, Toast.LENGTH_SHORT).show();
                List d = controllerHelper.getData();
                d.remove(position - 1);
                d.add(position - 1, "数据内部修改" + System.currentTimeMillis());
                controllerHelper.notifyChange();
                return true;
            }
        }
        return false;
    }

}
